layui.use(['table'], function () {
    const $ = layui.jquery,
        table = layui.table;


    if (JSON.parse(sessionStorage.getItem('memberData')) != null) {
        let obj = JSON.parse(sessionStorage.getItem('obj'));
        serverIP = obj.serverIP;
        serverApi = obj.serverApi;
        serverApi3 = obj.serverApi3;
        serverApi1 = obj.serverApi1;
        socketUrl6 = obj.socketUrl6;
    }

    //列表
    const tableIns = table.render({
        elem: '#list',
        url: serverApi + '/precord/findSysPharmacyVOAll',
        where: {
            fmemberId: $.cookie("memberId"),
            // fmemberId: 2105,
            name: ''
        },
        method: "POST",
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 200 //成功的状态码，默认：0
            , msgName: 'msg' //状态信息的字段名称，默认：msg
            , countName: 'totalElements' //数据总数的字段名称，默认：count
            , dataName: 'data' //数据列表的字段名称，默认：data
        },
        cellMinWidth: 95,
        height: "full-25",
        id: "dataTable",
        toolbar: '#toolbarDemo',
        defaultToolbar: [],
        cols: [[
            {field: 'name', title: '药店名称', minWidth: 200, align: 'center'},
            {field: 'detailsAddress', title: '详细地址', minWidth: 200, align: 'center'},
            {field: 'distance', title: '距离', width: 100, align: 'center'},
        ]]
    });

    //触发行单击事件
    table.on('row(test)', function (obj) {
        // console.log(obj.tr) //得到当前行元素对象
        console.log(obj.data) //得到当前行数据
        //obj.del(); //删除当前行
        //obj.update(fields) //修改当前行数据
        let pharmacyVO = {
            "id": obj.data.id,
            "name": obj.data.name,
        };
        sessionStorage.setItem('pharmacyVO', JSON.stringify(pharmacyVO));
        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    });

    //头工具栏事件
    table.on('toolbar(test)', function (obj) {
        switch (obj.event) {
            case 'search_btn':
                table.reload("dataTable", {
                    where: {
                        fmemberId: $.cookie("memberId"),
                        name: $(".name").val(),
                        province: $(".province").val(),
                        city: $(".city").val(),
                        region: $(".region").val(),
                    }
                });
                break;
        }
    });
});
